<?php
/*
 * Get the badges of someone
 */

// authenticate user first
F3::call('authentication.php');
	
if (F3::exists('auth_error'))
{
  // authentication failed
  return;
}

$uid = F3::get('PARAMS["user_id"]');

$param = array('1'=>$uid);

$r = DB::sql("SELECT * from user where id = ?",$param);

if(count($r)==0){
	header('HTTP/1.1 500 Internal Server Error');
	header("Content-Type: application/json");
	$err = array("error_message" => "No id is exist");
	echo json_encode($err);
	return;
}

$result = DB::sql("SELECT badges.name from badges join user_badges on badges.id=user_badges.bid where user_badges.uid = ?", $param);
header('HTTP/1.1 200');
header("Content-Type: application/json");
echo json_encode($result);
?>